package com.achen.workquene;

import com.achen.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;

/**
 * @author achen
 * @create 2021-07-25 4:22
 */
public class Provider {
    public static void main(String[] args) throws IOException {

        //获取连接对象
        Connection connection = RabbitMQUtils.getConnection();

        //获取通道对象
        Channel channel = connection.createChannel();

        //通过通道声明队列
        channel.queueDeclare("work", true, false, false, null);

        //生产消息
        for (int i = 0; i < 20; i++) {
            channel.basicPublish("", "work", null, (i + "-hello workquene").getBytes());
        }

        //关闭连接
        RabbitMQUtils.closeConnectionAndChannel(channel, connection);
    }
}
